import store from '@/store/index.js';

export default ({
  url, header, success, error,
  method = "POST", data = null, timeout = 6000,
}) => {
  let mixHeader = {
    // 'content-type': 'application/x-www-form-urlencoded',
    'content-type': 'application/json',
    'Authorization': store.state.token
  };
  for (let h in header) {
    mixHeader[h] = header[h];
  }
  return uni.request({
    url,
    header: mixHeader,
    timeout: timeout,
    data: data,
    method: method,
    success: function (res) {
      if (res.data.code === "0000") {
        success(res.data.data);
      } else {
        error(res.data.msg);
      }
    },
    error: function (res) {
      error("网络错误");
    }
  });
};
